package com.tyning.newcode.jz53_1;

/**
剑指 Offer 53 - I. 在排序数组中查找数字 I
统计一个数字在排序数组中出现的次数。



示例 1:

输入: nums = [5,7,7,8,8,10], target = 8
输出: 2
示例 2:

输入: nums = [5,7,7,8,8,10], target = 6
输出: 0


提示：

0 <= nums.length <= 105
-109 <= nums[i] <= 109
nums 是一个非递减数组
-109 <= target <= 109


注意：本题与主站 34 题相同（仅返回值不同）：https://leetcode-cn.com/problems/find-first-and-last-position-of-element-in-sorted-array/

 https://leetcode-cn.com/problems/zai-pai-xu-shu-zu-zhong-cha-zhao-shu-zi-lcof/
 */

/**
 * @author haining
 */
public class Solution {
    public static void main(String[] args) {

    }


    public int searchnew(int[] nums, int target) {
        int num = 0;
        for (int a : nums){
            if (target == a) {
                num = +num;
            }
        }
        return num;
    }

    public int search(int[] nums, int target) {
        if (nums == null || nums.length < 1){
            return 0;
        }
        if (target > nums[nums.length -1] || target < nums[0]){
            return 0;
        }
        int num = 0;
        for (int a : nums){
            if (a == target){
                num = num +1;
            }
        }

        return num;
    }

}
